//
//  ExchangeDetailsViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/9/4.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "ExchangeDetailsViewController.h"
#import "HYNetHelper.h"

@interface ExchangeDetailsViewController ()

@property (nonatomic, strong) ExchangeListEntity *exchangeEntity;

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *sellLabel;
@property (weak, nonatomic) IBOutlet UILabel *buyLabel;
@property (weak, nonatomic) IBOutlet UILabel *rateLabel;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UILabel *refLabel;

@property (weak, nonatomic) IBOutlet UILabel *dateTitle;
@property (weak, nonatomic) IBOutlet UILabel *typeTitle;
@property (weak, nonatomic) IBOutlet UILabel *sellTitle;
@property (weak, nonatomic) IBOutlet UILabel *buyTitle;
@property (weak, nonatomic) IBOutlet UILabel *rateTitle;
@property (weak, nonatomic) IBOutlet UILabel *statusTitle;
@property (weak, nonatomic) IBOutlet UILabel *refTitle;

@property (weak, nonatomic) IBOutlet UIButton *downButton;

@end

@implementation ExchangeDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = JFMainLocalizedString(@"transactions.details");
    
    self.dateTitle.text = JFMainLocalizedString(@"transactions.date");
    self.typeTitle.text = JFMainLocalizedString(@"transactions.Type");
    self.sellTitle.text = JFMainLocalizedString(@"exchange.from");
    self.buyTitle.text = JFMainLocalizedString(@"exchange.to");
    self.rateTitle.text = JFMainLocalizedString(@"transactions.rate");
    self.statusTitle.text = JFMainLocalizedString(@"transactions.status");
    self.refTitle.text = JFMainLocalizedString(@"transactions.ref_id");
    [self.downButton setTitle:JFMainLocalizedString(@"Download") forState:UIControlStateNormal];
    
    [self requestDetails];
}

- (void)updateData {
    self.refLabel.text = self.exchangeEntity.ref_id;
    self.typeLabel.text = self.exchangeEntity.type;
    self.sellLabel.text = [NSString stringWithFormat:@"%@ %@", self.exchangeEntity.sell_amount, self.exchangeEntity.sell_asset_symbol];
    self.buyLabel.text = [NSString stringWithFormat:@"%@ %@", self.exchangeEntity.buy_amount, self.exchangeEntity.buy_asset_symbol];
    self.statusLabel.text = self.exchangeEntity.status;
    self.rateLabel.text = self.exchangeEntity.rate;
    self.dateLabel.text = self.exchangeEntity.date;
}

- (void)requestDetails {
    WEAKSELF
    [HYNetHelper transactions2:self.transfer_id callback:^(JFResultVo *resultVo) {
        if (!resultVo.errorNo) {
            weakSelf.exchangeEntity = [ExchangeListEntity yy_modelWithDictionary:resultVo.results];
            [weakSelf updateData];
            
            [weakSelf.tableView reloadData];
        }
    }];
}

#pragma mark - Table view data source

- (IBAction)downAction:(id)sender {
    UIImage *image = [UIImage getImageWithScrollView:self.tableView];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil,nil);;
}
@end
